package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsNoticeAnnouncement;
import com.ruoyi.system.domain.news.query.NewsNoticeAnnouncementQuery;
import com.ruoyi.system.domain.news.vo.NewsNoticeAnnouncementVo;
import com.ruoyi.system.service.news.NewsNoticeAnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsNoticeAnnouncement")
@Api(value = "newsNoticeAnnouncementApiController", tags  = "通知公告Api")
public class NewsNoticeAnnouncementApiController extends BaseController {

	@Resource
	private NewsNoticeAnnouncementService newsNoticeAnnouncementService;

	@ApiOperation(value = "获取单个通知公告信息", notes = "获取单个通知公告信息")
	@GetMapping("/getById")
	public R<NewsNoticeAnnouncement> getById(@RequestParam(value = "id") Long id) {
		NewsNoticeAnnouncementQuery newsNoticeAnnouncementQuery = new NewsNoticeAnnouncementQuery();
		newsNoticeAnnouncementQuery.setId(id);
		List<NewsNoticeAnnouncementVo> newsNoticeAnnouncementList = newsNoticeAnnouncementService.getNewsNoticeAnnouncementList(newsNoticeAnnouncementQuery);
		if (newsNoticeAnnouncementList!=null&&newsNoticeAnnouncementList.size()>0) {
			return R.ok(newsNoticeAnnouncementList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取通知公告信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsNoticeAnnouncementVo>> list(@RequestBody NewsNoticeAnnouncementQuery newsNoticeAnnouncementQuery) {
        newsNoticeAnnouncementQuery.setIsEnable("1");
		List<NewsNoticeAnnouncementVo> newsNoticeAnnouncementList = newsNoticeAnnouncementService.getNewsNoticeAnnouncementList(newsNoticeAnnouncementQuery);
		return R.ok(new PageInfo<>(newsNoticeAnnouncementList));
	}
}
